package com.djl.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.djl.ud.FlDao;

public class ClassUpdateServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		FlDao fd =new FlDao();
		boolean bool = false;
		int pid = 0;
		HttpSession session = request.getSession();

		int id = (Integer)session.getAttribute("id");
		if(request.getParameter("pName")!=null){
				pid = Integer.parseInt(request.getParameter("pName"));
		}	
		String name = (String)request.getParameter("className");
		try {
			bool = fd.update(id, name, pid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(bool);
		if(bool){
			request.getRequestDispatcher("ClassServlet").forward(request, response);
		}else{
			request.getRequestDispatcher("err.jsp").forward(request, response);
		}
		

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
	}

}
